package sveta.applogic1;
import sveta.applogic.FilmHelper;
import sveta.applogic.NavigationHelper;
import sveta.model.Film;
import sveta.pages.*;

import java.util.List;

import org.openqa.selenium.By;


public class FilmHelper1 extends DriverBasedHelper implements FilmHelper {
	
	    public FilmHelper1(ApplicationManager1 manager) {
	   		   super(manager.getWebDriver());
	   		    
	    
	    
	  }

	  @Override
	  public String createFilm(Film film) {
	      pages.addFilmPage.clickHomeButton();	  
	      pages.addFilmPage.clickAddButton();	  
	      String currUrl = driver.getCurrentUrl();
	      pages.addFilmPage.setNumberField(film.getImdbNumber());
	      pages.addFilmPage.setNameField(film.getTitle());
	      pages.addFilmPage.setYearField(film.getYear());
	      pages.addFilmPage.clickSubmitButton();
	      return currUrl;
  

	  }

	  @Override
	  public int deleteFilm() {
		  pages.addFilmPage.clickHomeButton();
		  int count = pages.homePage.countFilm();
		  pages.homePage.chooseFilm();
		  pages.addFilmPage.clickRemoveButton();
		  return count;
		 

	  }

	  @Override
	  public void searchFilm (String title) {
		  pages.addFilmPage.clickHomeButton();
		  pages.addFilmPage.clickAddButton();
		  pages.addFilmPage.setSearchField(title);
		  pages.addFilmPage.clickSearchButton();
	
		    
	  }

	  @Override
	  public boolean isNotAddFilm(String currUrl) {
    	  return  (currUrl.equals(driver.getCurrentUrl()));

	  }
	  
	  @Override
	  public boolean getFilmInfo(Film film) {
		String filmInfo = pages.addFilmPage.getFilmInfo();  
		return (filmInfo.contains(film.getTitle()+" ("+film.getYear()+")"));
		
	  }

	  @Override
	  public boolean getTextAllert() {
		
		return (closeAlertAndGetItsText().matches ("^Are you sure you want to remove this[\\s\\S]$"));
		
	  }
	
	  @Override
	  public int getFilmCount() {
		return pages.addFilmPage.getFilmCount();
		
	  }

	  @Override
	  public boolean isTextNoFilm() {
		return(pages.addFilmPage.getTextNoFilm().contains("No movies where found."));
		
	  }

	  @Override
	  public boolean isDeletedFilm(int count) {
		int newCount = pages.homePage.countFilm();
		return (count == newCount+1);
	  }
	
}